home *** CD-ROM | disk | FTP | other *** search
/ SGI Performance Co-Pilot 1.3 / SGI Performance Co-Pilot 1.3.iso / dist / dist6.4 / pcp.idb / usr / sbin / pmgenmap.z / pmgenmap
Text File  |  1997-04-03  |  2KB  |  86 lines

  1. #!/bin/sh
  2. #
  3. # Generate a Performance Metrics Name Space Map from a specification file
  4. #
  5. # $Header: /isms/pcp/pcp/1.3/src/pmgenmap/RCS/pmgenmap.sh,v 2.1 1997/03/26 02:53:17 kenmcd Exp $
  6. #
  7.  
  8. prog=`basename $0`
  9. if [ $# -gt 1 -o "X$1" = "X-?" ]
  10. then
  11.     echo "Usage: $prog [infile]"
  12.     exit 1
  13. fi
  14. if [ $# -eq 0 ]
  15. then
  16.     pathnamename="<stdin>"
  17.     name="<stdin>"
  18. else
  19.     if [ ! -f $1 ]
  20.     then
  21.     echo "$prog: cannot open \"$1\""
  22.     exit 1
  23.     fi
  24.     pathname=`pwd`/$1
  25.     name=$1
  26. fi
  27.  
  28. cat <<End-of-File
  29. /*
  30.  * Performance Metrics Name Space Map
  31.  * Built by $prog from the file
  32.  * $name
  33.  * on `date`
  34.  *
  35.  * Do not edit this file!
  36.  */
  37.  
  38. End-of-File
  39.  
  40. nawk <$1 '
  41. $1 == "#"    { if (comment) text = text "\n *"
  42.           comment++
  43.           for (i = 2; i <= NF; i++)
  44.             text = text " " $i
  45.           next
  46.         }
  47. comment > 0    { if (comment == 1)
  48.             print "/*" text " */"
  49.           else
  50.             print "/*\n *" text "\n */"
  51.           comment = 0
  52.           text = ""
  53.         }
  54. NF == 0        { print; next }
  55. NF == 2 && $2 == "{"    { if (state != 0) {
  56.                 printf "[%s:%d] nested group?\n","'$1'",NR
  57.                 exit 1
  58.               }
  59.               printf "char *%s[] = {\n",$1
  60.               state = 1
  61.               ord = 0
  62.               next
  63.             }
  64. NF == 2 && state == 1    { printf "#define %s    %d\n",$2,ord
  65.               ord++
  66.               printf "    \"%s\",\n",$1
  67.               next
  68.             }
  69. NF == 1 && $1 == "}"    { printf "\n"
  70.               printf "};\n\n"
  71.               state = 0
  72.               next
  73.             }
  74.             { printf "[%s:%d] syntax error\n","'$name'",NR
  75.               exit 1
  76.             }
  77. END            { if (state) {
  78.                 printf "[%s:%d] unterminated group?\n","'$name'",NR
  79.                 exit 1
  80.               }
  81.               if (comment == 1)
  82.                 print "/*" text " */"
  83.               else if (comment > 1)
  84.                 print "/*\n *" text "\n */"
  85.             }'
  86.